package org.example.seat_management.Controller.api;

import org.example.seat_management.Entity.SeatInfo;
import org.example.seat_management.Service.SeatService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/seats")
public class SeatController {

    private final SeatService seatService;

    public SeatController(SeatService seatService) {
        this.seatService = seatService;
    }

    @PostMapping("/init")
    public void init(@RequestBody List<SeatInfo> seats) {
        seatService.batchInitialize(seats);
    }

    @PostMapping
    public void upsert(@RequestBody SeatInfo seat) {
        seatService.upsert(seat);
    }

    @PostMapping("/batch")
    public void batchUpsert(@RequestBody List<SeatInfo> seats) {
        seatService.batchUpsert(seats);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable Long id, @RequestBody SeatInfo seat) {
        seat.setId(id);
        seatService.update(seat);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        seatService.deleteById(id);
    }

    @GetMapping("/classroom/{classroomId}")
    public List<SeatInfo> listByClassroom(@PathVariable Long classroomId) {
        return seatService.listByClassroom(classroomId);
    }
}


